package com.hqyj.controller;

import com.hqyj.pojo.Dorm;

import com.hqyj.pojo.PageData;

import com.hqyj.service.DormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dorm")
public class DormController {
    @Autowired
    private DormService dormService ;

    //获取全部宿舍信息
    @RequestMapping("/list")
    public String getAll(ModelMap modelMap){
        List<Dorm> all =dormService.getAllDorm();
        modelMap.put("DORM",all);
        return "dorm/list" ;
    }

    @RequestMapping("/dormAdd")
    @ResponseBody
    public Map<String, String> addDorm(Dorm dorm){
       int i =dormService.insertDorm(dorm);
       Map<String,String> map =new HashMap<>();
           if(i != 0){
               map.put("msg","ok");
           }else {
               map.put("msg","no");
           }
           return map;
    }
    @RequestMapping("/dormDelete")
    @ResponseBody
    public Map<String, String> delDorm(Dorm dorm) {
        int i = dormService.deleteDorm(dorm);
        Map<String, String> map = new HashMap<>();
        if (i != 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "no");

        }
        return map;
    }

    @RequestMapping("/dormUpdate")
    @ResponseBody
    public Map<String, String> updataDorm(Dorm dorm) {
        int i = dormService.updateDorm(dorm);
        Map<String, String> map = new HashMap<>();
        if (i != 0) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "no");
        }
        return map;
    }

}
